﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using System.Data.SqlClient;

public partial class UserControl_Allocation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        // 将要显示的数据填充到数据集中
        DataSet alloc = new DataSet();
        SqlDataAdapter sda = new SqlDataAdapter();
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString);
        conn.Open();
        string alloc_id, store_id;
        alloc_id = ((HiddenField)((System.Web.UI.Page)System.Web.HttpContext.Current.Handler).FindControl("alloc_id")).Value;
        store_id = ((HiddenField)((System.Web.UI.Page)System.Web.HttpContext.Current.Handler).FindControl("store_id")).Value;
        
        sda = new  SqlDataAdapter("SELECT AllocationID, AllocationDate,StoreID From Allocation where AllocationID = '" + alloc_id + "' and StoreID = '" + store_id + "'",conn);
        sda.Fill(alloc, "Allocation");

        sda = new SqlDataAdapter("SELECT AllocationID,ISBN,StoreID,AllocationDetailID,Amount From AllocationDetail where AllocationID = '" + alloc_id + "' and StoreID = '" + store_id + "'", conn);
        sda.Fill(alloc, "AllocationDetail");

        sda = new SqlDataAdapter("SELECT BookName,ISBN,Author, Publisher From Book", conn);
        sda.Fill(alloc, "Book");

        sda = new SqlDataAdapter("SELECT StoreID,Name,Phone From Store where StoreID = '" + store_id + "'", conn);
        sda.Fill(alloc, "Store");

        // 设置报表源引用的报表文件和设置它的数据源
        ReportDocument AllocReport = new ReportDocument();
        string repPath = Server.MapPath("~/Reports/Allocation.rpt");
        AllocReport.Load(repPath);

        AllocReport.SetDataSource(alloc);

        // 设置报表查看控件的报表源
        CrystalReportViewer1.ReportSource = AllocReport;
    }
}
